package com.george.model.user.controller;

import com.george.model.user.entity.Employee;
import com.george.model.user.service.EmployeeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 *
 * </p>
 *
 * @author GeorgeChan 2019/5/16 14:26
 * @version 1.0
 * @since jdk1.8
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    private final Logger LOGGER = LoggerFactory.getLogger(EmployeeController.class);

    private final EmployeeService employeeService;

    @Autowired
    public EmployeeController(EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    @GetMapping("/get")
    public Employee get() {
        Employee employee = employeeService.findEmployeeById(1129219627605598209L);
        return employee;
    }

    @PostMapping("/add")
    public boolean add(){
        Employee employee = new Employee();
        employee.setAddress("安徽");
        employee.setEmail("lisi@126.com");
        employee.setName("李四");
        employee.setSalary(BigDecimal.valueOf(4000));
        employee.setSex(1);
        int res = employeeService.addEmployee(employee);
        return res > 0;
    }

    @DeleteMapping("/delete")
    public boolean delete(){
        // 逻辑删除
        boolean flag = employeeService.removeById(1129219627605598209L);
        return flag;
    }
}
